function x=pulseWidthSnd(samplingRate,secDuration,frequency,pulseWidth,amp,loPass,hiPass)

lengths=[length(frequency) length(pulseWidth) length(amp) length(loPass) length(hiPass)];
numPartials=max(lengths);

base = repmat([0:(secDuration*samplingRate)],numPartials,1);

if all(ismember(lengths,[1 numPartials]))
    freqs=expand(frequency,numPartials,size(base,2));
    pws=expand(pulseWidth,numPartials,size(base,2));
    amps=expand(amp,numPartials,size(base,2));
    loPass=expand(loPass,numPartials,1);
    hiPass=expand(hiPass,numPartials,1);
else
    lengths
    error('lengths of frequency, pulsewidth, loPass, and hiPass must be 1 or match')
end

x=double(sin(base.*freqs*2*pi/samplingRate)>(1-pws));

for i=1:numPartials
    x(i,:)=bandPass(x(i,:),loPass(i),hiPass(i),samplingRate);
end
x=sum(x.*amps,1);

attackDur=.01;

if secDuration>2*attackDur
    numAttackSamps=round(attackDur*samplingRate);
    attack=.5*cos(linspace(0,pi,numAttackSamps))+.5;
    x=x.*[attack ones(1,length(x)-2*numAttackSamps) fliplr(attack)];
end

x=2*((x-min(x))/range(x)-.5);


function out=expand(x,rows,cols)
if isscalar(x)
    out=x*ones(rows,cols);
elseif all(size(x)==[1 rows])
    out=repmat(x',1,cols);
else
    error('x must be scalar or [1 rows]')
end